package GUILayer;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.Frame;
import java.awt.GraphicsEnvironment;
import java.awt.Rectangle;
import java.awt.Toolkit;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.table.DefaultTableModel;
import javax.swing.ButtonGroup;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.JComboBox;
import javax.swing.JMenu;
import javax.swing.JToggleButton;
import javax.swing.BoxLayout;
import javax.swing.JRadioButton;
import javax.swing.JLabel;
import javax.swing.ListSelectionModel;
import javax.swing.UIManager;

import java.awt.Font;
import javax.swing.DefaultComboBoxModel;
import java.awt.FlowLayout;
import javax.swing.JTextArea;
import java.awt.CardLayout;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.Component;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.swing.Box;
import javax.swing.JTable;

import CtrLayer.JournalCtr;
import CtrLayer.SchemeCtr;


public class StudentGUI extends JFrame {

	private JPanel contentPane;
	private JTable table_1;
	private JScrollPane scrollPaneSchemesTable;
	private JournalCtr journalCtr;
	private SchemeCtr schemeCtr;
	private JPanel panel_1;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					StudentGUI frame = new StudentGUI();

					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public StudentGUI() {
	
		
		journalCtr=new JournalCtr();
		schemeCtr=new SchemeCtr();
		//Look and feel
		try {
            UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
            setIconImage(Toolkit.getDefaultToolkit().getImage(this.getClass().getResource("b4/advancedgui/menu/resources/green_arrow_right.png")));
        } catch (Exception ex) {
            Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE, null, ex);
           
        }
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		setExtendedState(Frame.MAXIMIZED_BOTH);
		
	      
		setBounds(100, 100, 580, 549);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(new BorderLayout(0, 0));

		
		JPanel panel_4 = new JPanel();
		contentPane.add(panel_4, BorderLayout.NORTH);
		
		
		
		JButton btnNewButton = new JButton("Select Date");
		
		panel_4.add(btnNewButton);
		
		final JLabel dateLabel = new JLabel("Date");
		panel_4.add(dateLabel);
		
		
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				new SessionCalendar(dateLabel);
			}
		});
		
		final JComboBox comboBoxRoom = new JComboBox();
		comboBoxRoom.setModel(new DefaultComboBoxModel(new String[] {"Room 1", "Room 2", "Room 3", "Room 4"}));
		panel_4.add(comboBoxRoom);
		
		JPanel panel_5 = new JPanel();
		contentPane.add(panel_5, BorderLayout.WEST);
		panel_5.setLayout(new BoxLayout(panel_5, BoxLayout.Y_AXIS));
		
		JPanel panel_2 = new JPanel();
		panel_5.add(panel_2);
		
		JPanel panel_6 = new JPanel();
		panel_5.add(panel_6);
		
		final JRadioButton generalInformationBut = new JRadioButton("General Information    ");
		panel_6.add(generalInformationBut);
		
		
		JPanel panel_7 = new JPanel();
		panel_5.add(panel_7);
		
		final JRadioButton nurseDocBut  = new JRadioButton("Nursing Documentation");
		panel_7.add(nurseDocBut);
		
		JPanel panel_8 = new JPanel();
		panel_5.add(panel_8);
		
		final JRadioButton labBut = new JRadioButton("Lab Scheme                   ");
		panel_8.add(labBut);
		
		JPanel panel_9 = new JPanel();
		panel_5.add(panel_9);
		
		final JRadioButton nutBut = new JRadioButton("Nutrition Risk Screening");
		panel_9.add(nutBut);
		
		JPanel panel_12 = new JPanel();
		panel_5.add(panel_12);
		
		final JRadioButton tempBut = new JRadioButton("Temperature Scheme    ");
		panel_12.add(tempBut);
		
		JPanel panel_13 = new JPanel();
		panel_5.add(panel_13);
		
		final JRadioButton bradenBut = new JRadioButton("Braden Scale                ");
		panel_13.add(bradenBut);
		
		JPanel panel_10 = new JPanel();
		panel_5.add(panel_10);
		
		JLabel lblNewLabel = new JLabel("    ");
		lblNewLabel.setFont(new Font("Tahoma", Font.PLAIN, 62));
		panel_10.add(lblNewLabel);
		
		JPanel panel_11 = new JPanel();
		contentPane.add(panel_11, BorderLayout.CENTER);
		panel_11.setLayout(new BorderLayout(0, 0));
		
		JPanel panel = new JPanel();
		panel_11.add(panel, BorderLayout.NORTH);
		
		final JComboBox comboBoxBed = new JComboBox();
		comboBoxBed.setModel(new DefaultComboBoxModel(new String[] {"Bed 1", "Bed 2", "Bed 3", "Bed 4"}));
		panel.add(comboBoxBed);
		
		Component horizontalStrut_1 = Box.createHorizontalStrut(55);
		panel.add(horizontalStrut_1);
		
		JButton btnNewButton_1 = new JButton("Print");
		panel.add(btnNewButton_1);
		
		Component horizontalStrut = Box.createHorizontalStrut(140);
		panel.add(horizontalStrut);
		
		 panel_1 = new JPanel();
		panel_11.add(panel_1, BorderLayout.CENTER);
		
	
		
		
		
		/**
		 * Groups the radio buttons so only 1 can be selected at a time
		 */
		ButtonGroup group = new ButtonGroup();
	    group.add(generalInformationBut);
	    group.add(nurseDocBut);
	    group.add(labBut);
	    group.add(nutBut);
	    group.add(tempBut);
	    group.add(bradenBut);
		panel_1.setLayout(new BoxLayout(panel_1, BoxLayout.Y_AXIS));
	    
	    
		table_1 = new JTable();
		table_1.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
		table_1.setRowSelectionAllowed(true);
		scrollPaneSchemesTable = new JScrollPane(table_1);
		table_1.setRowHeight(38);
		panel_1.add(scrollPaneSchemesTable);
		
		final JLabel statusLabel = new JLabel("");
		statusLabel.setFont(new Font("Tahoma", Font.PLAIN, 32));
		panel_1.add(statusLabel);
		
	    /**
	     * calls methods depending on which radio button is selected and returns the according information to the user interface
	     */
	    ActionListener action = new ActionListener(){
	    	public void actionPerformed(ActionEvent e){
	    		JRadioButton button = (JRadioButton)e.getSource();
	    		
    			int room_No=comboBoxRoom.getSelectedIndex()+1;
    			int bed_No=comboBoxBed.getSelectedIndex()+1;
    			String date=dateLabel.getText();
    			
    			
    			try{
	    		if(button.getText().equals("General Information    ")){
	    			

	    			
					String[] columnNames = { "       ", "                                    " };
	    			
	    			final String[][] generalInfo=journalCtr.getJournalInformationForSession(bed_No, room_No, date);
					DefaultTableModel model = new DefaultTableModel(generalInfo,columnNames);
					
				table_1.setModel(model);
	    			
	    	}else if(button.getText().equals("Nursing Documentation")){
	    		
	    		final String[][] nursingDocInfo	=schemeCtr.getNursingDocForSession(bed_No, room_No, date);
				String[] columnNames = { "       ", "                      ","                ","             " };
				
				DefaultTableModel model = new DefaultTableModel(nursingDocInfo,columnNames);
				table_1.setRowHeight(58);
				table_1.setModel(model);
	    		
	    	
	    	}else if(button.getText().equals("Lab Scheme                   ")){
	    		
	    		final String[][] labSchemesInfo	=schemeCtr.getLabSchemesForSession(bed_No, room_No, date);
				String[] columnNames = { "       ", "                      ","                ","             " };
				
				DefaultTableModel model = new DefaultTableModel(labSchemesInfo,columnNames);
				table_1.setRowHeight(40);
				table_1.setModel(model);
	    		
	    	
	    	}else if(button.getText().equals("Nutrition Risk Screening")){
	    		final String[][] riskSchemesInfo=schemeCtr.getNutritionRiskForSession(bed_No, room_No, date);
	    		String[] columnNames = { "", "                      " };
	    		
				DefaultTableModel model = new DefaultTableModel(riskSchemesInfo,columnNames);
				table_1.setRowHeight(40);
				table_1.setModel(model);
	    		
	    	
	    	}else if(button.getText().equals("Temperature Scheme    ")){
	    		
	    		new TempScheme(schemeCtr.getTemperature(bed_No, room_No, date),schemeCtr.getPulse(bed_No, room_No, date),
	    				schemeCtr.getBloodPressure(bed_No, room_No, date),schemeCtr.getRespiration(bed_No, room_No, date));
	    		
	    		
	    		
	    		
	    		
	    	}else if(button.getText().equals("Braden Scale                ")){
	    
	    		final String[][] braScale=schemeCtr.getBradenScaleForSession(bed_No, room_No, date);
	    		String[] columnNames = { "", "                      " };
	    		
				DefaultTableModel model = new DefaultTableModel(braScale,columnNames);
				table_1.setRowHeight(40);
				table_1.setModel(model);
				
				
				
	    	}
	    		statusLabel.setText("");
	    		
    			}
    			
    			catch(Exception ex)
    			{
    				statusLabel.setText("Session is not found, please select proper date.");
    			}


	    	}	
	    	
	    };
	    
	    generalInformationBut.addActionListener(action);
	    nurseDocBut.addActionListener(action);
	    labBut.addActionListener(action);
	    nutBut.addActionListener(action);
	    tempBut.addActionListener(action);
	    bradenBut.addActionListener(action);
	    

	}

}
